:- use_module(library(http/http_open)).
%:- use_module(library(rdf_write)).
:- use_module(library(sgml)).


%:- dynamic in_rdf/0.

start :-
	http_open('http://localhost:5000', InStream, []),
	%open('temp.xml',write,FileStream,[encoding(utf8)]),
	%copy_stream_data(InStream, FileStream),

	%close(InStream),
	%close(FileStream),

	new_sgml_parser(MyParser,[]),
	set_sgml_parser(MyParser,file('FileErr.err')),
	set_sgml_parser(MyParser,number(integer)),
	sgml_parse(MyParser,
		   [%document(Term),
		    source(InStream),
		    parse(file),
		    %parse(content),
		    call(begin, on_begin),
		    call(end, on_end)
		   ]),
/*	nl,write('TERM:'),nl,
	write(Term),nl,nl,
	Term = [element(Name,[Attr = Value], Arr)],
*/	
	close(InStream).


on_begin('comment', _, _) :- nl,write('START COMMENT'),nl.

on_begin('data', Attr, Parser) :- 
	nl,write('START DATA PARSING:'),nl,
	%write('Attr:'),nl,write(Attr),nl,
	sgml_parse(Parser,
		  [parse(content),
		   call(begin, on_begin)
		  ]).

on_begin('var',Attr,_):-
	Attr = [name = VarName],
	nl,write('VarName :'),write(VarName),nl.

on_begin('number',Attr,Parser):-
	sgml_parse(Parser,
		   [document(Content),
		    parse(content)
		   ]),
	Content = [VarContent],
	nl,write('VarContent :'),write(VarContent),nl.

on_begin(Tag,Attr,Parser):-
	nl,write('TAG START:'),write(Tag),nl,
	%sgml_parse(Parser,
	%	   [document(Content),
	%	    parse(content)
	%	   ]),
	write('Attr:'),write(Attr),nl.
	%write('Content:'),write(Content),nl.


on_end('comment', _) :- nl,write('COMMENT END'),nl.

on_end(Tag, _) :- nl,write('TAG END:'), write(Tag),nl.

?- start.








